package com.giscloud.amp.controller.sys;

import com.giscloud.amp.entity.dto.LoginLogDTO;
import com.giscloud.amp.service.sys.LoginLogService;
import com.giscloud.commons.model.Result;
import com.giscloud.datasource.page.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author:gxd
 * @Description:
 * @Date: 22:12 2018/3/11
 * @Modified By:
 */
@SuppressWarnings("SpringJavaAutowiringInspection") //加这个注解让IDE 不报: Could not autowire
@RestController
public class LoginLogController {
	
	private static final Logger log = LoggerFactory.getLogger(LoginLogController.class);
    @Autowired
    private LoginLogService loginLogRemoteClient;

    @RequestMapping(value="/amp/loginLog/getList",method = RequestMethod.POST)
    public PageInfo getList(@RequestBody LoginLogDTO loginLogDTO) {
        return loginLogRemoteClient.getList(loginLogDTO);
    }

    @RequestMapping(value="/amp/loginLog/delete",method = RequestMethod.POST)
    public Result delete(String logId){
        Result result = new Result();
        if(StringUtils.isBlank(logId)){
            result.setMsg("删除失败，日志ID不能为空");
            result.setCode(-1);
            result.setSuccess(false);
            return result;
        }
        try {
            if(loginLogRemoteClient.delete(Long.parseLong(logId)) >= 1){
                result.setMsg("删除成功");
                result.setCode(0);
                result.setSuccess(true);
            }else{
                result.setMsg("删除失败");
                result.setCode(-1);
                result.setSuccess(false);
            }
        }catch (Exception e){
            result.setMsg("删除失败");
            result.setCode(-1);
            result.setSuccess(false);
        }
        return result;
    }

}
